using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using BLT;

namespace SpriteTest
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        Menu menu;
        SpriteFont font;
        Texture2D bgtexture;
        BLT.Level level1;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            font = Content.Load<SpriteFont>("Lucida Console");

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            menu = new Menu(Vector2.Zero, new Vector2(100, 100), Color.Blue, Color.Chocolate, "hi", font);

            menu.addOption("a", new Menu.optionDelegate(doNothing));
            menu.addOption("b", new Menu.optionDelegate(doNothing));
            menu.addOption("c", new Menu.optionDelegate(doNothing));

            /*menu.addOption("a", new Menu.optionDelegate(doNothing));
            menu.addOption("b", new Menu.optionDelegate(doNothing));
            menu.addOption("c", new Menu.optionDelegate(doNothing));
            menu.addOption("a", new Menu.optionDelegate(doNothing));
            menu.addOption("b", new Menu.optionDelegate(doNothing));
            menu.addOption("c", new Menu.optionDelegate(doNothing));
            menu.addOption("a", new Menu.optionDelegate(doNothing));
            menu.addOption("b", new Menu.optionDelegate(doNothing));
            menu.addOption("c", new Menu.optionDelegate(doNothing));*/

            menu.addOption("exit", new Menu.optionDelegate(doNothing));

            Sprite testSprite1 = new Sprite(Content.Load<Texture2D>("Bitmap2"), Vector2.Zero);

            bgtexture = Content.Load<Texture2D>("bg");
            level1 = new Level(bgtexture, Color.White);

            testSprite1.m_maxSpeed = new Vector2(500, 500);
            testSprite1.m_moveSpeed = 1;
            testSprite1.AssignButtonToMovement(Keys.A, MoveDirection.RIGHT);
            level1.AddSprite(testSprite1);
        }

        public void doNothing(string s)
        {
            if( s.Equals("exit") )
                this.Exit();
        }

        protected override void UnloadContent()
        {
        }

        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            menu.update();
            level1.Update(gameTime);

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin();

           
            //test.Draw(spriteBatch);
            
            level1.Draw(spriteBatch);
            menu.draw(spriteBatch);

            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}
